//
//  MovieTableViewCell.m
//  DouBan
//
//  Created by dllo on 16/6/24.
//  Copyright © 2016年 zuzhiming. All rights reserved.
//

#import "MovieTableViewCell.h"
#import "MovieModel.h"
#import "UIImageView+WebCache.h"
#import "Masonry.h"
@interface MovieTableViewCell ()
@property (nonatomic, retain) UIImageView *backGroudImageView;

@property (nonatomic, retain) UIImageView *movieImageView;

@property (nonatomic, retain) UILabel *movieLabel;


@end

@implementation MovieTableViewCell

- (void)dealloc
{
    [_movieImageView release];
    [_movieLabel release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.backGroudImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_backGroudImageView];
        [_backGroudImageView release];
        
        self.movieImageView = [[UIImageView alloc] init];
        [self.backGroudImageView addSubview:_movieImageView];
        [_movieImageView release];
        
        self.movieLabel = [[UILabel alloc] init];
        [self.backGroudImageView addSubview:_movieLabel];
        [_movieLabel release];
        
    }
    return self;
}

- (void)setModel:(MovieModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
    [self.movieImageView sd_setImageWithURL:[NSURL URLWithString:_model.pic_url] placeholderImage:[UIImage imageNamed:@"picholder"]];
    self.movieLabel.text = _model.movieName;
    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
//    self.movieImageView.backgroundColor = [UIColor greenColor];
//    self.movieLabel.backgroundColor = [UIColor redColor];
    
    self.backGroudImageView.image = [UIImage imageNamed:@"bg_eventlistcell"];
    
    [self.backGroudImageView makeConstraints:^(MASConstraintMaker *make) {
       make.edges.offset(UIEdgeInsetsMake(6, 10, 8, 10));
        
    }];
    
    [self.movieImageView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.backGroudImageView.top).offset(5);
        make.left.equalTo(self.backGroudImageView.left).offset(8);
        make.width.equalTo(100);
        make.bottom.equalTo(self.backGroudImageView.bottom).offset(-5);
    }];
    
    [self.movieLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.backGroudImageView.top).offset(45);
        make.left.equalTo(self.movieImageView.right).offset(16);
        make.right.equalTo(self.backGroudImageView.right).offset(-5);
        make.height.equalTo(50);
    }];
    
}



- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
